package cn.tsoft.taobao.adapter;



import java.util.List;
import java.util.Map;



import cn.tsoft.taobao.ui.R;
import cn.tsoft.taobao.util.AsyncImageLoader;
import cn.tsoft.taobao.util.ImageDownloader;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

/**
 * 商品目录信息
 * @author wanggj
 *
 */
public class ProductItemAdapter  extends BaseAdapter {
	private int[] mTo;
    private String[] mFrom;
	private List<? extends Map<String, ?>> mData;
	private Context cotext;
    private int mResource;
    private LayoutInflater mInflater;
    private final ListView listView;
//    private ImageView img = null;  
    private TextView title = null;  
    private TextView num = null;
    private TextView time = null;
    private TextView status = null;
//    private AsyncImageLoader asyncImageLoader;
    
    private final ImageDownloader imageDownloader ;
    
    public ProductItemAdapter(Context context,List<? extends Map<String, ?>> mData,
    		int mResource,String[] mFrom,int[] mTo,ListView listView) {
		super();
		this.cotext = context;
		this.listView = listView;
		this.mTo = mTo;
		this.mFrom = mFrom;
		this.mData = mData;
		this.mResource = mResource;
		this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);;
//		this.asyncImageLoader = new AsyncImageLoader();
		imageDownloader = new ImageDownloader();
	}

    @Override
	public View getView(int position, View convertView, ViewGroup parent) {
			convertView = mInflater.inflate(this.mResource, null);
//			img = (ImageView)convertView.findViewById(mTo[0]);
			title = (TextView)convertView.findViewById(mTo[0]);
			num= (TextView)convertView.findViewById(mTo[1]);
			time = (TextView)convertView.findViewById(mTo[2]);
			if(mTo.length == 4){
				status = (TextView)convertView.findViewById(mTo[3]);
			}
			String imageUrl = (String) mData.get(position).get("item_image");
			
//	       imageDownloader.download(imageUrl,  img);
	       
	       title.setText((String)mData.get(position).get("title"));
			Log.v("MyAdapter",position+"");
			Log.v("title", title.getText().toString());
			num.setText(num.getText()+mData.get(position).get("num").toString());
			time.setText(time.getText()+mData.get(position).get("time").toString());
			return convertView;
	}
	@Override
	public int getCount() {
		return mData.size();
	}

	@Override
	public Object getItem(int position) {
		return this.mData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

}
